#include "RLResultWriter.h"
#include <fstream>
#include <iomanip>

namespace algo
{
    bool RLResultWriter::writeToFile(const std::string& filename, const algobase::TrajectoryCoords& trajectory)
    {
        std::ofstream outfile(filename);
        if (!outfile.is_open()) {
            return false;
        }

        // Write header
        outfile << "Timestamp,TotalTime,TotalDistance,Lon,Lat,Depth,Heading,Speed,MomentaryTime,MomentaryDistance\n";

        outfile << std::fixed << std::setprecision(6);

        for (const auto& point : trajectory)
        {
            outfile << point.cTime << ","
                    << point.tTime << ","
                    << point.tDistance << ","
                    << point.mCoordZ[0] << ","
                    << point.mCoordZ[1] << ","
                    << point.mCoordZ[2] << ","
                    << point.mHeading << ","
                    << point.mSpeed << ","
                    << point.mTime << ","
                    << point.mDistance << "\n";
        }

        outfile.close();
        return true;
    }
}